﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[DateRangeIsInTimeDiv] 
(
	-- Add the parameters for the function here
	@StartDatetoCheck datetime,
	@EndDatetoCheck datetime,
	@TimeDiv nvarchar(100),
	@UserEntityID int = 0,
	@InstitutionID int = 0
)
RETURNS bit
AS
BEGIN
	-- Declare the return variable here
	DECLARE @RETVAL bit

	IF (@EndDatetoCheck >= dbo.GetTimeDivDate(@TimeDiv,'START',@UserEntityID,@InstitutionID) AND @StartDatetoCheck <= dbo.GetTimeDivDate(@TimeDiv,'END',@UserEntityID,@InstitutionID))
		SET @RETVAL = 1
	ELSE SET @RETVAL = 0

	RETURN @RETVAL

END